#!/usr/bin/env python
# encoding: utf-8
# @author: Lin Han
# @contact: voldemort22@126.com
# @file: process.py
# @time: 2021/4/29 17:40
# @desc:
from typing import Tuple
import json
import requests

from utils.md5_tools import getFileMd5
from utils.oss.oss_tools import download_file_from_oss
from views.configs import BACKEND_PORT, BACKEND_IP, CATPART_OSS_ADDRESS, STP_OSS_ADDRESS, GLTF_OSS_ADDRESS, STL_OSS_ADDRESS


def convert_catpart(file_path: str) -> Tuple:
    pass


def history_clamp_process(number: str):
    # 调用历史夹具的查询接口，拿到历史夹具数据
    result = requests.get(url=f"http://{BACKEND_IP}:{BACKEND_PORT}/api/history_clamp/v1/history_clamp?number={number}")
    data = result.json()['data']
    download_file_from_oss(oss_file_name=data["file"][CATPART_OSS_ADDRESS])
    data["file"][STP_OSS_ADDRESS], data["file"][STL_OSS_ADDRESS], data["file"][GLTF_OSS_ADDRESS] = convert_catpart(data["file"][CATPART_OSS_ADDRESS])
    # 转化好了，计算MD5值并上传回亚马逊
    data["file"]["catpartMD5"] = getFileMd5(data["file"][CATPART_OSS_ADDRESS])

    data["file"]["stpMD5"] = getFileMd5(data["file"][STP_OSS_ADDRESS])
    data["file"]["stlMD5"] = getFileMd5(data["file"][STL_OSS_ADDRESS])
    data["file"]["gltfMD5"] = getFileMd5(data["file"][GLTF_OSS_ADDRESS])


